import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import store from './store'
import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'



// Create Vue app
const app = createApp(App)

// Use plugins
app.use(router)
app.use(store)
app.use(Antd)

// 初始化 wujie 通信
if (window.__POWERED_BY_WUJIE__) {
  // 获取主应用传递的数据
  if (window.$wujie?.props) {
    const { token, userInfo } = window.$wujie.props
    console.log('从主应用获取的数据:', { token, userInfo })
    localStorage.setItem('child_app_token', token || '')
    localStorage.setItem('child_app_user_info', JSON.stringify(userInfo || {}))
  }
  
  // 注册通信事件
  window.$wujie?.bus.$on('main-app:message', (data: any) => {
    console.log('收到主应用消息:', data)
  })
}

// Mount app
app.mount('#app')

// 导出相关生命周期钩子
export const bootstrap = () => {
  console.log('子应用启动')
}

export const mount = () => {
  console.log("子应用挂载");
}

export const unmount = () => {
  console.log('子应用卸载')
}